//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __BOOTMODULEMGR__
#define __BOOTMODULEMGR__

#include <elasys_server.h>
#include <driver.h>
#include <bootmods.h>

#define MAX_LENGTH_BOOTMODUE_NAME 32

typedef struct ModuleInfo {
    char * szName;
    PVoid  pFile;
    Int32  size;
} ModuleInfo;

class CBootModuleMgr : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();

public:
     CBootModuleMgr(ModuleInfo * pModInfos,
                    Int32 numberOfModules)
            : m_curIndex(-1),
              m_pModInfos(pModInfos),
              m_numberOfModules(numberOfModules) {}

    ~CBootModuleMgr() {}
    ECode Constructor();

private:
    ECode Helper_Current(
        /* [out] */ BMFileInfo * pFileInfo);

    ECode Helper_MoveNext();
    ECode Helper_Reset();

    ECode Helper_GetFileInfo(
        /* [in] */ char * szName,
        /* [out] */ BMFileInfo * pFileInfo);

public:
    Int32        m_curIndex;
    ModuleInfo * m_pModInfos;
    Int32        m_numberOfModules;
};

#endif // __BOOTMODULEMGR__

